load("@wod_deps//:requirements.bzl", "requirement")
load("@rules_python//python:versions.bzl", "gen_python_config_settings")
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")


package(
    default_applicable_licenses = ["//waymo_open_dataset:license"],
    default_visibility = ["//visibility:public"],
)

py_package(
    name = "all_python_modules",
    # Only include these Python packages.
    # '.' will be replaced with '/' , ex. waymo_open_dataset.math corresponds //waymo_open_dataset/math
    packages = [
        "waymo_open_dataset",
    ],
    # All targets to include into the package.
    # Output from `bazel query 'kind(py_library,//...) - attr(testonly, 0, //...)'`
    deps = [
        "//waymo_open_dataset:dataset_cc_proto",
        "//waymo_open_dataset:dataset_proto_py_pb2",
        "//waymo_open_dataset:label_cc_proto",
        "//waymo_open_dataset:label_proto_py_pb2",
        "//waymo_open_dataset/common:status",
        "//waymo_open_dataset/data_conversion:scenario_conversion",
        "//waymo_open_dataset/math:aabox2d",
        "//waymo_open_dataset/math:box2d",
        "//waymo_open_dataset/math:exactfloat",
        "//waymo_open_dataset/math:math_util",
        "//waymo_open_dataset/math:polygon2d",
        "//waymo_open_dataset/math:segment2d",
        "//waymo_open_dataset/math:vec2d",
        "//waymo_open_dataset/math:vec3d",
        "//waymo_open_dataset/metrics:breakdown_generator",
        "//waymo_open_dataset/metrics:config_util",
        "//waymo_open_dataset/metrics:detection_metrics",
        "//waymo_open_dataset/metrics:hungarian",
        "//waymo_open_dataset/metrics:iou",
        "//waymo_open_dataset/metrics:matcher",
        "//waymo_open_dataset/metrics:metrics_utils",
        "//waymo_open_dataset/metrics:mot",
        "//waymo_open_dataset/metrics:motion_metrics",
        "//waymo_open_dataset/metrics:motion_metrics_utils",
        "//waymo_open_dataset/metrics:segmentation_metrics",
        "//waymo_open_dataset/metrics:tracking_metrics",
        "//waymo_open_dataset/metrics/ops:py_metrics_ops",
        "//waymo_open_dataset/metrics/ops:utils",
        "//waymo_open_dataset/metrics/python:config_util_py",
        "//waymo_open_dataset/metrics/python:detection_metrics",
        "//waymo_open_dataset/metrics/python:keypoint_metrics",
        "//waymo_open_dataset/metrics/python:matcher",
        "//waymo_open_dataset/metrics/python:motion_metrics",
        "//waymo_open_dataset/metrics/python:tracking_metrics",
        "//waymo_open_dataset/metrics/python:wod_detection_evaluator",
        "//waymo_open_dataset/protos:box_cc_proto",
        "//waymo_open_dataset/protos:box_proto_py_pb2",
        "//waymo_open_dataset/protos:breakdown_cc_proto",
        "//waymo_open_dataset/protos:breakdown_proto_py_pb2",
        "//waymo_open_dataset/protos:camera_segmentation_cc_proto",
        "//waymo_open_dataset/protos:camera_segmentation_metrics_cc_proto",
        "//waymo_open_dataset/protos:camera_segmentation_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:camera_segmentation_proto_py_pb2",
        "//waymo_open_dataset/protos:camera_segmentation_submission_cc_proto",
        "//waymo_open_dataset/protos:camera_segmentation_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:compressed_lidar_cc_proto",
        "//waymo_open_dataset/protos:compressed_lidar_proto_py_pb2",
        "//waymo_open_dataset/protos:conversion_config_cc_proto",
        "//waymo_open_dataset/protos:conversion_config_proto_py_pb2",
        "//waymo_open_dataset/protos:end_to_end_driving_data_proto_py_pb2",
        "//waymo_open_dataset/protos:end_to_end_driving_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:keypoint_cc_proto",
        "//waymo_open_dataset/protos:keypoint_proto_py_pb2",
        "//waymo_open_dataset/protos:keypoints_metrics_cc_proto",
        "//waymo_open_dataset/protos:keypoints_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:keypoints_submission_cc_proto",
        "//waymo_open_dataset/protos:keypoints_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:map_cc_proto",
        "//waymo_open_dataset/protos:map_proto_py_pb2",
        "//waymo_open_dataset/protos:metrics_cc_proto",
        "//waymo_open_dataset/protos:metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:motion_metrics_cc_proto",
        "//waymo_open_dataset/protos:motion_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:motion_submission_cc_proto",
        "//waymo_open_dataset/protos:motion_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:occupancy_flow_metrics_cc_proto",
        "//waymo_open_dataset/protos:occupancy_flow_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:occupancy_flow_submission_cc_proto",
        "//waymo_open_dataset/protos:occupancy_flow_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:scenario_cc_proto",
        "//waymo_open_dataset/protos:scenario_proto_py_pb2",
        "//waymo_open_dataset/protos:segmentation_cc_proto",
        "//waymo_open_dataset/protos:segmentation_metrics_cc_proto",
        "//waymo_open_dataset/protos:segmentation_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:segmentation_proto_py_pb2",
        "//waymo_open_dataset/protos:segmentation_submission_cc_proto",
        "//waymo_open_dataset/protos:segmentation_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:sim_agents_metrics_cc_proto",
        "//waymo_open_dataset/protos:sim_agents_metrics_proto_py_pb2",
        "//waymo_open_dataset/protos:sim_agents_submission_cc_proto",
        "//waymo_open_dataset/protos:sim_agents_submission_proto_py_pb2",
        "//waymo_open_dataset/protos:submission_cc_proto",
        "//waymo_open_dataset/protos:submission_proto_py_pb2",
        "//waymo_open_dataset/protos:vector_cc_proto",
        "//waymo_open_dataset/protos:vector_proto_py_pb2",
        "//waymo_open_dataset/utils:box_utils",
        "//waymo_open_dataset/utils:camera_segmentation_utils",
        "//waymo_open_dataset/utils:frame_utils",
        "//waymo_open_dataset/utils:geometry_utils",
        "//waymo_open_dataset/utils:keypoint_data",
        "//waymo_open_dataset/utils:keypoint_draw",
        "//waymo_open_dataset/utils:occupancy_flow_data",
        "//waymo_open_dataset/utils:occupancy_flow_grids",
        "//waymo_open_dataset/utils:occupancy_flow_metrics",
        "//waymo_open_dataset/utils:occupancy_flow_renderer",
        "//waymo_open_dataset/utils:occupancy_flow_vis",
        "//waymo_open_dataset/utils:plot_maps",
        "//waymo_open_dataset/utils:range_image_utils",
        "//waymo_open_dataset/utils:trajectory_utils",
        "//waymo_open_dataset/utils:transform_utils",
        "//waymo_open_dataset/utils:womd_camera_utils",
        "//waymo_open_dataset/utils:womd_lidar_utils",
        "//waymo_open_dataset/utils/compression:delta_encoder",
        "//waymo_open_dataset/utils/sim_agents:converters",
        "//waymo_open_dataset/utils/sim_agents:submission_specs",
        "//waymo_open_dataset/utils/sim_agents:test_utils",
        "//waymo_open_dataset/utils/sim_agents:visualizations",
        "//waymo_open_dataset/v2",
        "//waymo_open_dataset/v2:column_types",
        "//waymo_open_dataset/v2:component",
        "//waymo_open_dataset/v2:dataframe_utils",
        "//waymo_open_dataset/v2:typing_utils",
        "//waymo_open_dataset/v2/perception:base",
        "//waymo_open_dataset/v2/perception:box",
        "//waymo_open_dataset/v2/perception:camera_image",
        "//waymo_open_dataset/v2/perception:context",
        "//waymo_open_dataset/v2/perception:keypoints",
        "//waymo_open_dataset/v2/perception:lidar",
        "//waymo_open_dataset/v2/perception:pose",
        "//waymo_open_dataset/v2/perception:segmentation",
        "//waymo_open_dataset/v2/perception/compat_v1:box",
        "//waymo_open_dataset/v2/perception/compat_v1:camera_image",
        "//waymo_open_dataset/v2/perception/compat_v1:context",
        "//waymo_open_dataset/v2/perception/compat_v1:interfaces",
        "//waymo_open_dataset/v2/perception/compat_v1:keypoints",
        "//waymo_open_dataset/v2/perception/compat_v1:lidar",
        "//waymo_open_dataset/v2/perception/compat_v1:pose",
        "//waymo_open_dataset/v2/perception/compat_v1:segmentation",
        "//waymo_open_dataset/v2/perception/utils:lidar_utils",
        "//waymo_open_dataset/wdl_limited/camera:libcamera_model.so",
        "//waymo_open_dataset/wdl_limited/camera/ops:py_camera_model_ops",
        "//waymo_open_dataset/wdl_limited/camera_segmentation:camera_segmentation_metrics",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:estimators",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:interaction_features",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:map_metric_features",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:metric_features",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:metrics",
        "//waymo_open_dataset/wdl_limited/sim_agents_metrics:trajectory_features",
    ],
)

gen_python_config_settings()

py_wheel(
    name = "wheel",
    description_file = "pypi_description.md",
    distribution = "waymo-open-dataset-tf-2-12-0",
    python_tag = "py3",
    # Should be in-sync with //requirements.in
    requires = [
        "absl-py==1.4.0",
        "dask[dataframe]==2023.3.1",
        "einsum==0.3.0",
        "google-auth==2.16.2",
        "immutabledict==2.2.0",
        "jax==0.4.13",
        "jaxlib==0.4.13",
        "matplotlib==3.6.1",
        "numpy==1.23.5",
        "pandas==1.5.3",
        "pillow==9.2.0",
        "plotly==5.13.1",
        "pyarrow==16.0.0",
        "scikit-image==0.20.0",
        "scikit-learn==1.2.2",
        "setuptools==67.6.0",
        "tensorflow==2.13",
        "tensorflow_probability==0.21.0",
        "visu3d==1.5.1",
        "dacite==1.8.1"
    ],
    homepage = "https://github.com/waymo-research/waymo-open-dataset",
    version = "1.6.7",
    deps = [
        ":all_python_modules",
    ],
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python :: 3.10',
        'Topic :: Scientific/Engineering',
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
        'Topic :: Software Development',
        'Topic :: Software Development :: Libraries',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ]
)

py_wheel(
    name = "deeplab2_wheel",
    distribution = "deeplab2-for-wod",
    python_tag = "py3",
    requires = [
        "immutabledict==2.2.0",
        "numpy==1.21.5",
        "tensorflow==2.11",
    ],
    homepage = "https://github.com/google-research/deeplab2",
    version = "1.6.1",
    deps = [
        '@deeplab2//:deeplab2',
    ]
)

py_binary(
    name = "auditwheel_wrapper",
    srcs = ["auditwheel_wrapper.py"],
    deps = [
        requirement("auditwheel"),
        requirement("patchelf"),
        requirement("tensorflow"),
    ],
)

genrule(
    name = "wheel_manylinux",
    srcs = [
        ":wheel",
    ],
    outs = ["auditwheel_manylinux"],
    cmd = "./$(location :auditwheel_wrapper) repair --plat=manylinux_2_28_x86_64 $(location :wheel) -w $(OUTS)",
    executable = True,
    tools = [
        ":auditwheel_wrapper",
    ],
)
